/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package etherblocks.mods.survival.entitysystem.systems;

import etherblocks.game.entitysystem.*;
import etherblocks.mods.survival.entitysystem.components.*;
import java.util.List;

/**
 *
 * @author Philipp
 */
public class HungerSystem implements EntitySystem
{

    public void onNextFrameCalculation(EntityMap entityMap, float lastTimePerFrame) {
        List<Entity> entities = entityMap.getEntities(HungerComponent.class);
        for(Entity entity : entities)
        {
            HungerComponent hunger = entity.getComponent(HungerComponent.class);
            float hungerValue = hunger.getHunger();
            hungerValue += hunger.getRegeneration() * lastTimePerFrame;
            entity.setComponent(new HungerComponent(hungerValue, hunger.getMaxHunger(), hunger.getRegeneration()));
            HealthComponent health = entity.getComponent(HealthComponent.class);
            if(health != null && hungerValue < 0)
            {
                entity.setComponent(new HealthComponent(health.getHealth() + hungerValue, health.getMaxHealth(), health.getRegeneration()));
            }
        }
    }
    
}
